# -*- conding:UTF-8 -*-

'''
@ Project: one-group
@ File: jwt_utils.py
@ Author: 孙博
@ Date：2022/6/8 20:17

'''
from flask import current_app
import jwt


def genera_token(payload, expire, algorithms='HS256'):
    key = current_app.config.get('SERCRET_KEY')
    if 'expire' in payload:
        payload['expire'] = str(expire)
    try:
        token = jwt.encode(payload, key, algorithms)
        return token
    except Exception as e:
        print('token err', e)
        return e


def check_token(token):
    key = current_app.config.get('SERCRET_KEY')
    try:
        payload = jwt.decode(token, key, algorithms='HS256')
        print('校验token的payload-----》', payload)
        return payload

    except Exception as e:
        print('校验token的报错信息', e)
        return None


# def genera_token(payload, expire, algorithms='HS256'):
#     key = current_app.config.get('SERCRET_KEY')
#     if 'expire' in payload:
#         payload['expire'] = str(expire)
#     try:
#         token = jwt.encode(payload, key, algorithms)
#         return token
#     except Exception as e:
#         print('token err', e)
#         return e
#
#
# def check_token(token):
#     key = current_app.config.get('SERCRET_KEY')
#     payload = jwt.decode(token, key, algorithms='HS256')
#     return payload


